﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class admin_SelectProduct : System.Web.UI.Page
{
    static PagedDataSource pagedDataSource = new PagedDataSource();
    static List<Product> productList = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Product product = new Product();
            productList = ProductManager.FindBlurProduct(product);
            pagedDataSource.DataSource = productList;
            pagedDataSource.PageSize = 10;
            pagedDataSource.CurrentPageIndex = 0;
            pagedDataSource.AllowPaging = true;
            this.DataList2.DataSource = pagedDataSource;
            this.DataList2.DataBind();
        }
    }
    protected void DataList2_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "selectData")
        {
            Product product = ProductManager.FindByProductId(Convert.ToInt32(e.CommandArgument.ToString()));
            ClientScript.RegisterStartupScript(this.GetType(), "", "var rel=new Array('" + e.CommandArgument.ToString() + "','" + product.ProductName+ "'); window.returnValue = rel; window.close();", true);
        }
    }
    protected void DataList2_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Footer)
        {
            if (pagedDataSource.IsFirstPage)
            {
                ((LinkButton)e.Item.FindControl("LinkButton5")).Enabled = false;
            }
            if (pagedDataSource.IsLastPage)
            {
                ((LinkButton)e.Item.FindControl("LinkButton6")).Enabled = false;
            }
        }
    }
    protected void LinkButton5_Click(object sender, EventArgs e)
    {
        pagedDataSource.DataSource = productList;
        pagedDataSource.PageSize = 10;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.CurrentPageIndex--;
        DataList2.DataSource = pagedDataSource;
        DataList2.DataBind();
    }
    protected void LinkButton6_Click(object sender, EventArgs e)
    {
        pagedDataSource.DataSource = productList;
        pagedDataSource.PageSize = 10;
        pagedDataSource.AllowPaging = true;
        pagedDataSource.CurrentPageIndex++;
        DataList2.DataSource = pagedDataSource;
        DataList2.DataBind();
    }
    protected void btnFind_Click(object sender, EventArgs e)
    {
        if (txtProductName.Text != null && txtProductName.Text != "")
        {
            Product product = new Product();
            product.ProductName = txtProductName.Text.Trim();
            productList = ProductManager.FindBlurProduct(product);
            pagedDataSource.DataSource = productList;
            pagedDataSource.PageSize = 10;
            pagedDataSource.CurrentPageIndex = 0;
            pagedDataSource.AllowPaging = true;
            this.DataList2.DataSource = productList;
            this.DataList2.DataBind();
        }
    }
}
